Call g_convert(), not g_convert() with fallback, since Emacs is happier if
authorOwen Taylor <otaylor@redhat.com>
Wed, 25 Feb 2004 23:05:48 +0000 (23:05 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 25 Feb 2004 23:05:48 +0000 (23:05 +0000)
Wed Feb 25 15:36:50 2004  Owen Taylor  <otaylor@redhat.com>

        * gdk/x11/gdkselection-x11.c (gdk_utf8_to_compound_text_for_display):
        Call g_convert(), not g_convert() with fallback, since Emacs is
        happier if we reject the COMPOUND_TEXT request and it can
        then ask for UTF-8. (#114527)

        * gtk/gtkselection.c (gtk_selection_data_set_text): When
        TEXT is requested, if COMPOUND_TEXT fails, fall back to STRING.

gdk/x11/gdkselection-x11.c
gtk/gtkselection.c

index 859fca7c67a740e1f3b046f7039d2acd06fd6d6d..ce11b5a40a8bff65ffc42861a3fdb3c1d947cd28 100644 (file)
@@ -819,15 +819,19 @@ gdk_utf8_to_compound_text_for_display (GdkDisplay  *display,
 
   if (need_conversion)
     {
-      locale_str = g_convert_with_fallback (tmp_str, -1,
-                                           charset, "UTF-8",
-                                           NULL, NULL, NULL, &error);
+      locale_str = g_convert (tmp_str, -1,
+                             charset, "UTF-8",
+                             NULL, NULL, &error);
       g_free (tmp_str);
 
       if (!locale_str)
        {
-         g_warning ("Error converting from UTF-8 to '%s': %s",
-                    charset, error->message);
+         if (!(error->domain = G_CONVERT_ERROR &&
+               error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
+           {
+             g_warning ("Error converting from UTF-8 to '%s': %s",
+                        charset, error->message);
+           }
          g_error_free (error);
 
          if (encoding)
index c0417ca82c991b1368874f7957262b9dca8b5e5c..7314e3f22f11550ac4e2712160042bc4ea3faf57 100644 (file)
@@ -813,6 +813,55 @@ init_atoms (void)
     }
 }
 
+static gboolean
+selection_set_string (GtkSelectionData *selection_data,
+                     const gchar      *str,
+                     gint              len)
+{
+  gchar *tmp = g_strndup (str, len);
+  gchar *latin1 = gdk_utf8_to_string_target (tmp);
+  g_free (tmp);
+  
+  if (latin1)
+    {
+      gtk_selection_data_set (selection_data,
+                             GDK_SELECTION_TYPE_STRING,
+                             8, latin1, strlen (latin1));
+      g_free (latin1);
+      
+      return TRUE;
+    }
+  else
+    return FALSE;
+}
+
+static gboolean
+selection_set_compound_text (GtkSelectionData *selection_data,
+                            const gchar      *str,
+                            gint              len)
+{
+  gchar *tmp;
+  guchar *text;
+  GdkAtom encoding;
+  gint format;
+  gint new_length;
+  gboolean result = FALSE;
+  
+  tmp = g_strndup (str, len);
+  if (gdk_utf8_to_compound_text_for_display (selection_data->display, tmp,
+                                            &encoding, &format, &text, &new_length))
+    {
+      gtk_selection_data_set (selection_data, encoding, format, text, new_length);
+      gdk_free_compound_text (text);
+      
+      result = TRUE;
+    }
+
+  g_free (tmp);
+
+  return result;
+}
+
 /**
  * gtk_selection_data_set_text:
  * @selection_data: a #GtkSelectionData
@@ -831,8 +880,6 @@ gtk_selection_data_set_text (GtkSelectionData     *selection_data,
                             const gchar          *str,
                             gint                  len)
 {
-  gboolean result = FALSE;
-  
   if (len < 0)
     len = strlen (str);
   
@@ -843,48 +890,22 @@ gtk_selection_data_set_text (GtkSelectionData     *selection_data,
       gtk_selection_data_set (selection_data,
                              utf8_atom,
                              8, (guchar *)str, len);
-      result = TRUE;
+      return TRUE;
     }
   else if (selection_data->target == GDK_TARGET_STRING)
     {
-      gchar *tmp = g_strndup (str, len);
-      gchar *latin1 = gdk_utf8_to_string_target (tmp);
-      g_free (tmp);
-
-      if (latin1)
-       {
-         gtk_selection_data_set (selection_data,
-                                 GDK_SELECTION_TYPE_STRING,
-                                 8, latin1, strlen (latin1));
-         g_free (latin1);
-         
-         result = TRUE;
-       }
-
+      return selection_set_string (selection_data, str, len);
     }
   else if (selection_data->target == ctext_atom ||
           selection_data->target == text_atom)
     {
-      gchar *tmp;
-      guchar *text;
-      GdkAtom encoding;
-      gint format;
-      gint new_length;
-
-      tmp = g_strndup (str, len);
-      if (gdk_utf8_to_compound_text_for_display (selection_data->display, tmp,
-                                                &encoding, &format, &text, &new_length))
-       {
-         gtk_selection_data_set (selection_data, encoding, format, text, new_length);
-         gdk_free_compound_text (text);
-
-         result = TRUE;
-       }
-
-      g_free (tmp);
+      if (selection_set_compound_text (selection_data, str, len))
+       return TRUE;
+      else if (selection_data->target == text_atom)
+       return selection_set_string (selection_data, str, len);
     }
-  
-  return result;
+
+  return FALSE;
 }
 
 /**